;; The first four lines of this file were added by Dracula.
;; They tell DrScheme that this is a Dracula Modular ACL2 program.
;; Leave these lines unchanged so that DrScheme can properly load this file.
#reader(planet "reader.rkt" ("cce" "dracula.plt") "modular" "lang")
(require "igrayscale.lisp")

(require "icommon.lisp")
(require "iimage.lisp")

(module MGrayscale
  (include-book "avl-rational-keys" :dir :teachpacks)
  (import IImage)
  (import ICommon)
  
  (defun GetNewColor(r g b)
    (let* ((maximum (max (max r g) b))
            (minimum (min (min r g) b ))
            (newcolor (floor (+ maximum minimum) 2)))
           newcolor))
  
(defun GrayscalePixel (tree x y width height)
    (let* ((nextX (getNextXCoordinate x width))
           (nextY (getNextYCoordinate x y width))
           (pixel (getPixel tree x y)))
      (let* ((r        (car pixel))
             (g        (cadr pixel))
             (b        (caddr pixel))
             (newColor (GetNewColor r g b)))
        (if (isValidPixel nextX nextY width height)
            (GrayscalePixel (insertPixel tree x y newColor newColor newColor) nextX nextY width height)
            (insertPixel tree x y newColor newColor newColor)))))
  
  (defun MainGrayscale(tree)
    (let* ((Width  (getWidth tree))
           (Height (getHeight tree)))
          (mv (GrayscalePixel tree 1 Height Width Height) (list "Sucessfully grayscaled image."))))
  
  (export IGrayscale))